﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Base.DAL;
using Base.BLL;
using Base.Util;
using System.Data;
using Ay.Framework.WPF;
using MPSystem.Models;
using ADX.Views;

namespace MPSystem.Views.YFQ
{
    /// <summary>
    /// DP_test_Condition4.xaml 的交互逻辑 综采工作阻力历史数据分析曲线查询
    /// </summary>
    public partial class DataQuery_ZCZJFH_Conditon : Page
    {
        public Dictionary<string, string> Cond = new Dictionary<string, string>();
        public static DataQuery_ZCZJFH_Conditon _Me = null;
        public static DataQuery_ZCZJFH_Conditon Me
        {
            get
            {
                if (_Me == null)
                {
                    _Me = new DataQuery_ZCZJFH_Conditon();
                    _Me.UpdateCond();
                }
                return _Me;
            }
            set { _Me = value; }
        }
        int gzmbh = 0;

        public DataQuery_ZCZJFH_Conditon()
        {
            InitializeComponent();
            LoadData();
            Me = this;
        }
                
        public void LoadData()
        {
            CB1.IsEnabled = false;
            CB2.IsEnabled = false;
            CB3.IsEnabled = false;
            RQ1.IsChecked = true;
            RQ3.IsChecked = true;
            LoadBH();
            Begtime.SelectedDate = DateTime.Now;
            Endtime.SelectedDate = DateTime.Now;
        }
        #region 读取压力分站编号
        private bool isFirstLoad = true;
        public void LoadBH()
        {
            if (isFirstLoad || gzmbh != ZCYLPage_Freq.gzmbh)
            {
                RQ1_Click(this, null);
                isFirstLoad = false;
                gzmbh = ZCYLPage_Freq.gzmbh;
            }
        }
        #endregion
        public void UpdateCond()
        {
            Cond.Clear();
            try
            {
                if (!CB_WZ.ItemsSource.IsNullAndTrimAndEmpty() && CB_WZ.SelectedIndex < 0)
                {
                    AyMessageBox.Show("请选编号或位置");
                    return;
                }

                //状态标志位
                int s = 0, s1 = 1, s2 = 2, s3 = 4, s4 = 8, s5 = 16;
                //单柱选择情况,0代表整柱，不为0时，其二进制从低到高位分别代表左、右、不使用
                string SFZJ = "0";
                //if (RQ4.IsChecked == true)
                //{
                //    if (CB1.IsChecked == true) s = s | s1;
                //    if (CB2.IsChecked == true) s = s | s2;
                //    if (CB3.IsChecked == true) s = s | s3;
                //    SFZJ = s.ToString();
                //}
                if (CB1.IsChecked == true) s = s1;
                if (CB2.IsChecked == true) s = s2;
                if (CB3.IsChecked == true) s = s3;

                if (RQ1.IsChecked == true)
                {
                    if (CB_WZ.SelectedValue != null)
                    {
                        Cond.Add("bh", CB_WZ.SelectedValue.ToString());
                    }
                    else
                    {
                        Cond.Add("bh", "-1");
                    }
                    Cond.Add("wz", "");
                }
                else
                {
                    Cond.Add("bh", "0");
                    Cond.Add("wz", CB_WZ.SelectedValue.ToString());
                }
                Cond.Add("sfzj", SFZJ);//是否整架
                Cond.Add("dtStart", Begtime.Text.ToString());
                Cond.Add("dtEnd", Endtime.Text.ToString());
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex);
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.CloseParentWindow();

        }
        
        #region 按键控制事件
        private void RQ1_Click(object sender, RoutedEventArgs e)
        {
            if (RQ1.IsChecked == true)
            {
                //if (gzmbh == ZCYLPage_Freq.gzmbh) return;
                //gzmbh = ZCYLPage_Freq.gzmbh;
                var lWz = ConfigService.GetZcWz(ZCYLPage_Freq.gzmbh);
                DataTable tempTable = new DataTable();
                DataColumn dc1 = new DataColumn("bh", Type.GetType("System.Int32"));
                DataColumn dc2 = new DataColumn("mc", Type.GetType("System.String"));
                tempTable.Columns.Add(dc1);
                tempTable.Columns.Add(dc2);
                //CB_WZ.ItemsSource = null;
                //CB_WZ.ItemsSource = tempTable.DefaultView;
                foreach (var r in lWz)
                {
                    DataRow dr0 = tempTable.NewRow();
                    dr0["bh"] = r.YLFJBH;
                    dr0["mc"] = r.YLFJBH;
                    tempTable.Rows.Add(dr0);
                }
                tempTable.AcceptChanges();
                CB_WZ.ItemsSource = tempTable.DefaultView;
                if (lWz.Count() > 0)
                    CB_WZ.SelectedIndex = 0;
                tempTable.Dispose();
            }
        }

        private void RQ2_Click(object sender, RoutedEventArgs e)
        {
            if (RQ2.IsChecked == true)
            {
                string lWz = "全部,上部,中部,下部";
                string[] arrWz = lWz.Split(',');
                DataTable tempTable = new DataTable();
                DataColumn dc1 = new DataColumn("bh", Type.GetType("System.String"));
                DataColumn dc2 = new DataColumn("mc", Type.GetType("System.String"));
                tempTable.Columns.Add(dc1);
                tempTable.Columns.Add(dc2);
                //CB_WZ.ItemsSource = null;
                //CB_WZ.ItemsSource = tempTable.DefaultView;
                foreach (var r in arrWz)
                {
                    DataRow dr0 = tempTable.NewRow();
                    dr0["bh"] = r;
                    dr0["mc"] = r;
                    tempTable.Rows.Add(dr0);
                }
                tempTable.AcceptChanges();
                CB_WZ.ItemsSource = tempTable.DefaultView;
                CB_WZ.SelectedIndex = 0;
                tempTable.Dispose();
            }
        }

        private void RQ3_Click(object sender, RoutedEventArgs e)
        {
            if (RQ3.IsChecked == true && CB3!=null)
            {
                CB1.IsEnabled = false;
                CB2.IsEnabled = false;
                CB3.IsEnabled = false;
                CB1.IsChecked = false;
                CB2.IsChecked = false;
                CB3.IsChecked = false;

            }
        }

        private void RQ4_Click(object sender, RoutedEventArgs e)
        {
            if (RQ4.IsChecked == true)
            {
                CB1.IsEnabled = true;
                CB2.IsEnabled = true;
                CB3.IsEnabled = true;
                CB1.IsChecked = true;
                //CB2.IsChecked = true;
                //CB3.IsChecked = true;
            }
        }
        #endregion

        #region 多选下拉框使用
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        private Dictionary<string, object> _items;
        private Dictionary<string, object> _selectedItems;
        public Dictionary<string, object> Items
        {
            get
            {
                return _items;
            }
            set
            {
                _items = value;
                NotifyPropertyChanged("Items");
            }
        }
        public Dictionary<string, object> SelectedItems
        {
            get
            {
                return _selectedItems;
            }
            set
            {
                _selectedItems = value;
                NotifyPropertyChanged("SelectedItems");
            }
        }
        private void Submit()
        {
            foreach (KeyValuePair<string, object> s in SelectedItems)
                MessageBox.Show(s.Key);
        }
        #endregion

    }
}
